<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>WebSocket 示例</title>
  <script type="text/javascript">
    function WebSocketTest()
    {
      if ("WebSocket" in window)
      {
        alert("本浏览器支持 WebSocket");
        let ws = new WebSocket("ws://localhost:9998/echo");
        ws.onopen = function ()
        {
          ws.send("发送数据");
          alert("WebSocket 正在发送数据");
        };
        ws.onmessage = function (event)
        {
          let received = event.data;
          alert("WebSockt 收到数据");
        };
        ws.onclose = function ()
        {
          alert("WebSockt 连接关闭");
        };
      } else
      {
        alert("浏览器不支持 WebSocket");
      }
    }
  </script>
</head>

<body>
  <div id="see">
    <a href="javascript:WebSocketTest()">运行WebSocket</a>
  </div>
</body>

</html>